<script setup>
import homeApi from '@/api/home'
import { ref,onMounted } from 'vue'
// 获取轮播图数据
const bannerList = ref([])
//封装获取bannerList数据的方法
const getBannerList = async ()=>{
    const res = await homeApi.getBanner()
    bannerList.value = res.result
    //console.log(bannerList.value);
}
//onMounted函数在组件挂载后执行
onMounted(()=>getBannerList())
</script>
<template>
  <div class="home-banner">
    <!-- element-plus通用轮播图组件el-carousel -->
    <el-carousel height="500px">
      <el-carousel-item v-for="item in bannerList" :key="item.id">
        <img :src="item.imgUrl" alt="">
      </el-carousel-item>
    </el-carousel>
  </div>
</template>



<style scoped lang='scss'>
.home-banner {
  width: 1240px;
  height: 500px;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 98;

  img {
    width: 100%;
    height: 500px;
  }
}
</style>